﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class configshop_searchresult : System.Web.UI.Page
    {
        string id="";
        string keyword = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dealrequest();
                bindbbs();
                bindshop();
            }

        }
        private void dealrequest()
        { 
            id = AliApi.appUserId;
            if (Request.Params["id"] != null)
            {
                cbuser u = cbuser.Find(" recid =  " + Request.Params["id"].ToString());
                if (u.Count > 0)
                {
                    id = u.cbuserid.ToString();
                }
            }
            if (id == "")
            {
                //return ""; //为了方便测试,暂时注销
            }
            cbshopcss sc = cbshopcss.findorcreate(id);
            string css = sc.getstylestring();
            Literalcss.Text = css;

            if (this.Request.Params["keyword"] != null)
            {
                keyword = this.Request.Params["keyword"].ToString();
                keyword = keyword.Replace("'", "");
                keyword = keyword.Replace("declare ", "");
            }
        }
        /// <summary>
        /// 论坛搜索结果
        /// </summary>
        private void bindbbs()
        {
            
            string sql = "";
            keyword = zfunction.ReplaceKeyWord(keyword);
            sql = " select top 1000 * from vcblist where isprivate != 1 ";
            sql += " and cbcataid in ( select cbcataid from cbcata where createuserid ='" +id+ "' ) ";
            sql += " and ( 1=2 ";
                sql += " or  cbtitle like '" + keyword + "' ";
                sql += " or cbcontent like '" + keyword + "' ";
            sql += " )";

            sql += "  order by chakanshu desc, jccreatedate desc ,jccreatetime desc ";
            DataTable dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            WebPager_bbs.DataSource = dt;
            WebPager_bbs.DataBind();
        }
        /// <summary>
        /// 商品搜索结果
        /// </summary>
        private void bindshop()
        {
            string keyword = "";
            if (this.Request.Params["keyword"] != null)
            {
                keyword = this.Request.Params["keyword"].ToString();
            }
            string sql = "";
            keyword = zfunction.ReplaceKeyWord(keyword);
            sql = " select top 100  * from Vitem   ";
            sql += " where taobaouserid ='" + id + "'  ";
            sql += " and ( 1=2 ";
            sql += " or  taobaotitle like '" + zfunction.ReplaceKeyWord(keyword) + "' ";
            sql += " or cbusernickname = '" + keyword + "' ";
            sql += " or taobaoNickName = '" + keyword + "' ";
            sql += " )";

            sql += "  order by  taobaomodified desc ";
            DataTable dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            WebPager_shop.DataSource = dt;
            WebPager_shop.DataBind();
        }


    }
}
